<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
      layout:decorator="share/admin">

<head>
</head>

<div layout:fragment="content">

    <div id="tab-system" class="HuiTab">
        <div class="text-c">
            <form id="search">
                <select class="select select-box inline selCate" name="catePath">
                    <option value="" path="/0">全部分类</option>
                </select>
                 日期范围：
                <input type="text" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'logmax\')||\'%y-%M-%d\'}' })" id="logmin" class="input-text Wdate" style="width:120px;">
                -
                <input type="text" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'logmin\')}',maxDate:'%y-%M-%d' })" id="logmax" class="input-text Wdate" style="width:120px;">
                <input type="text" name="title" placeholder="标题" style="width:250px" class="input-text">
                <button id="btnSearch" class="btn btn-success" type="button"><i class="Hui-iconfont"></i> 搜索</button>
            </form>
        </div>

        <div class="tabCon" style="display:block;padding-top:10px;">
            <table class="table table-border table-bordered table-hover table-bg table-sort" id="list">
                <thead>
                <tr>
                    <th style="width:70px;">标题</th>
                    <th>分类</th>
                    <th>内容</th>
                    <th>下载地址</th>
                    <th>状态</th>
                    <th> 创建时间</th>
                    <th style="width:70px;text-align:center;"><a class="btn btn-primary radius" href="javascript:;" onclick="save()">添加</a> </th>
                </tr>
                </thead>
            </table>
        </div>

    </div>
</div>
<script type="text/javascript" layout:fragment="scripts" th:inline="none">
    var tbSettings = $.extend($.datatablesSettings, {
          "sAjaxSource": "videoPost",
          "columns": [
                     { "data": "title" },
                     { "data": "cateName" },
                     { "data": "body" },
                     { "data": "downloadUrl" },
                     { "data": "state" },
                     { "data": "created" },
                     { "data": "id", "sClass": "text-c f-18" }//操作按钮列
                  ],
                  "columnDefs": [{
                          "targets": 5, "data": "Value", "render": function (data, type, full, meta) {
                              return new Date(data).format('yyyy-MM-dd');
                          }
                      }, {
                          "targets": 6, "render": function (data, type, row) {
                              return '<a style="text-decoration:none" onclick="save(\'' + data + '\');" href="javascript:;" title="编辑"><i class="Hui-iconfont"></i></a>\
                                          <a class="ml-5" style="text-decoration:none"  onclick="del('+ row.id + ');"  href="javascript:;" title="删除"><i class="Hui-iconfont"></i></a>';
                          }
                      },
                          //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
                          { "orderable": false, "aTargets": [6] },// 制定列不参与排序
                          { sDefaultContent: '', aTargets: ['_all'] }
                  ]
        });
    var tb = $('#list').dataTable(tbSettings);
    // tb.fnDraw();
    basicData.getCateTree(".selCate", null ,true);

    $('#btnSearch').click(function () {
            //这里重新设置参数
            tbSettings.fnServerParams = function (aoData) {
                var para = $("#search").serializeObject();
                aoData._rand = Math.random();
                for (var attr in para){
                    aoData.push({ "name": attr, "value": para[attr]});
                }
                // alert(JSON.stringify(aoData));
            }
            //搜索就是设置参数，然后销毁datatable重新再建一个
            tb.fnDestroy(false);
            tb = $('#list').dataTable(tbSettings);
            //搜索后跳转到第一页
            tb.fnPageChange(0);
        });

    function save(id) {
        var url = 'videoPost/save'+ (id? '/'+id:'');
        layer_show('视频发布', url, '600', '450');
    }
    function del(id) {
        if (!confirm('确定删除吗？')) return;

        $lv.actionJson('videoPost/del?id='+id, function (r) {
            if (r && r.code ==1) tb.fnDraw(true);
            else $lv.toast('删除失败！');
        });
    }

</script>